package com.nuc.controller;

import com.nuc.vo.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class UserController {

    /**
     * postmapping只能接受post请求,增加操作
     * @param user
     * @return
     */
    @PostMapping("/user")
    public User InsertUser(User user) {
        System.out.println("user add...");
        return user;
    }

    /**
     * getmapping只能接受get请求，查询操作
     * @return
     */
    @GetMapping("/user")
    public List<User> findAllUser() {
        System.out.println("findall...");
        User user1 = new User(1001, "dasds", "12323");
        User user2 = new User(1002, "dthjytds", "1267563");
        User user3 = new User(1003, "dasdsikop", "15623290983");

        List<User> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);
        list.add(user3);

        return list;
    }

    /**
     * 完成删除操作
     * @param uid
     * @return
     */
    @DeleteMapping("/user/{uid}")
    public User deleteUser(@PathVariable Integer uid) {
        System.out.println("delete User....." + uid);
        User user = new User(1001, "dasds", "12323");
        return user;
    }

    /**
     * 完成更新操作
     * @param user
     * @return
     */
    @PutMapping("/user")
    public User updateUser(User user) {
        System.out.println("update User...");
        return user;
    }
}
